<style>
    .layui-form .layui-form-item .layui-inline .layui-form-label {
        width: 100px;
    }
</style>
<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >标题：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="title" placeholder="title" autocomplete="off"
                       maxlength="50" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >内容：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="desc" placeholder="desc" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="search"><i class="iconfont icon-chaxun"></i>Search</button>
                <a href="{:url('noticeAdd')}" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe608;</i>Add</a>
            </div>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="dataTable" lay-filter="dataTable" ></table>
</div>

<script>
    layui.use(['form',  'table'], function () {
        var tableIn = layui.table.render({
            elem: '#dataTable',
            height: 'full-99',
            cellMinWidth: '80',
            url: "{:url('notice')}",
            method:'POST',
            cols: [[
                { type: 'numbers'},
                { field: 'title', align: 'left',  title: '标题', width: 300},
                { field: 'text', align: 'left',  title: '内容'},
                { field: 'ctime',align: 'center', title: '创建时间',width:180,
                    templet: function (d) {
                        return layui.util.toDateString(d.ctime * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                { title: '操作',width:150,
                    templet: function (d) {
                    var html = '<a class="layui-btn layui-btn-xs" href="{:url(\'noticeEdit\')}?id=' + d.id + '">Edit</a>';
                        html += '<a class="layui-btn layui-btn-xs option-del layui-btn-danger" data-id="' + d.id + '">删除</a>';
                        return html;
                    }, align: 'center'
                }
            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100],
        });
        layui.form.on('submit(search)', function (data) {
            layui.table.reload('dataTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                },
                method:'POST'
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //角色删除
        $(document).on('click', '.option-del', function () {
            var id = $(this).attr('data-id');
            layer.confirm('您确认要删除么？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                //去删除
                JsPost("{:url('Server/noticeDel')}", { 'id': id }, function (res) {
                    if (res.status) {
                        layer.msg('删除成功');
                        tableIn.reload();
                    } else {
                        layer.msg(res.msg);
                    }
                });
            }, function () {
                layer.close(1);
            });
        });
    });
</script>